<?php

namespace app\web\validate;

use app\web\jwt\JwtsMac;
use think\Validate;

class Login extends Validate
{
    protected $rule = [
        'code' => 'require',
        'equipment' => 'check_require',
    ];

    protected $field = [
        'code' => '授权码',
        'equipment' => '设备授权码',
    ];

    /**
     * 验证设备码
     * @param $value
     * @param $data
     * @return bool|void
     */
    protected function check_require($value, $data){
        if(!empty($value)){
            //验证授权码是否有效
            $data = JwtsMac::verifyToken($value);
            if(!$data) return '设备授权码出错！';
        }
        return true;
    }
}